package com.midou.administration.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.midou.administration.bo.ToTheNumberOfDays;
import com.midou.administration.bo.UserBo;
import com.midou.administration.entity.Comment;
import com.midou.administration.mapper.CommentMapper;
import com.midou.administration.utils.BadWordUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.midou.administration.utils.BadWordUtil.replaceBadWord;

@Service
public class CommentServiceImpl {

    @Autowired
    private CommentMapper commentMapper;

    //查询商家所对应评论
    public Page queryComment(UserBo userBo)
    {
         List<Comment> list=commentMapper.queryComment(userBo.getCommentPage(),userBo.getComStar(),userBo.getUserBusinessId());
        for (Comment comment : list) {
            Set<String> s = BadWordUtil.words;
            Map<String,String> map = BadWordUtil.wordMap;
            String string = comment.getComContent();
            Set<String> set = BadWordUtil.getBadWord(string, 2);
            String str= replaceBadWord(string,string.length(),"*");
            comment.setComContent(str);
            System.out.println(str);
        }
         userBo.getCommentPage().setRecords(list);
         return userBo.getCommentPage();
    }

  /**
   * 查询该商户的平均分
   * @param id
   * @return
   */
  public int doBuidFindAVGStar(int id){
      int AvgStar = commentMapper.doBuidFindAVGStar(id);
      return AvgStar;
    }

  /**
   * 返回最近7天的评分
   * @param id
   * @return
   */
  public List<ToTheNumberOfDays> doDayFindAvgStar(int id){
    List<ToTheNumberOfDays> list = commentMapper.doDayFindAvgStar(id);
    return list;
  }
}
